package com.xiao.controller;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.xiao.entity.AlarmContentInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

/**
 * @author Xiao
 * @version 1.0
 * @description
 * @date 2022/6/22 21:19
 */

@Controller
@RequestMapping("/fm")
@Slf4j
public class FreemarkerController {
    /**
     * 多城市-仅含城市维度
     * @param model
     * @return
     */
    @RequestMapping("/city1")
    public String testDemo1(Model model) {
        List<AlarmContentInfo> infoList = getInfoList(1);
        model.addAllAttributes(getParamMap(1, "城市补贴预警", infoList));
        return "city";
    }

    /**
     * 多城市-含城市之外的维度
     * @param model
     * @return
     */
    @RequestMapping("/city2")
    public String testDemo2(Model model) {
        List<AlarmContentInfo> infoList = getInfoList(2);
        model.addAllAttributes(getParamMap(1, "城市补贴预警", infoList));
        return "city";
    }

    /**
     * 单城市-城市维度
     * @param model
     * @return
     */
    @RequestMapping("/city3")
    public String testDemo3(Model model) {
        List<AlarmContentInfo> infoList = getInfoList(3);
        model.addAllAttributes(getParamMap(2, "上海补贴预警", infoList));
        return "city";
    }

    /**
     * 单城市-城市分群维度
     * @param model
     * @return
     */
    @RequestMapping("/city4")
    public String testDemo4(Model model) {
        List<AlarmContentInfo> infoList = getInfoList(4);
        model.addAllAttributes(getParamMap(2, "战略进攻补贴预警", infoList));
        return "city";
    }

    private Map<String,Object> getParamMap(int contentType, String cityNames, List<AlarmContentInfo> infoList) {
        Map<String, Object> paramMap = Maps.newHashMap();
        paramMap.put("contentType", contentType);
        paramMap.put("title", cityNames);
        paramMap.put("infoList", infoList);
        paramMap.put("detailUrl","https://www.baidu.com/");
        return paramMap;
    }

    private List<AlarmContentInfo> getInfoList(int type) {
        List<AlarmContentInfo> infoList = Lists.newArrayList();
        switch (type) {
            case 1:
                infoList.add(getAlarmContentInfo(2, "上海,杭州", 6, "B补强度=10%,C补强度=20%,订单达成率=30%,净G达成率=40%,近7天日均消耗=2000.58元", "一级", true));
                infoList.add(getAlarmContentInfo(4, "上海,杭州,北京", 4, "B补强度=10%,C补强度=20%,订单达成率=30%,净G达成率=40%", "二级", true));
                infoList.add(getAlarmContentInfo(1, "上海", 4, "B补强度=10%,C补强度=20%,订单达成率=30%,净G达成率=40%", "三级", true));
                break;
            case 2:
                infoList.add(getAlarmContentInfo(1, "战略进攻", 4, "B补强度=10%,C补强度=20%,订单达成率=30%,净G达成率=40%", "一级", false));
                infoList.add(getAlarmContentInfo(3, "苏州,深圳,大连", 4, "B补强度=10%,C补强度=20%,订单达成率=30%,净G达成率=40%", "二级", true));
                infoList.add(getAlarmContentInfo(4, "战略进攻,上海,杭州", 6, "B补强度=10%,C补强度=20%,订单达成率=30%,净G达成率=40%,近7天日均消耗=2000.58元", "三级", false));
                break;
            case 3:
                infoList.add(getAlarmContentInfo(1, "上海", 6, "B补强度=10%,C补强度=20%,订单达成率=30%,净G达成率=40%,近7天日均消耗=2000.58元", "一级", true));
                infoList.add(getAlarmContentInfo(1, "上海", 5, "B补强度=10%,C补强度=20%,订单达成率=30%,净G达成率=40%,近7天日均消耗=2000.58元", "二级", true));
                infoList.add(getAlarmContentInfo(1, "上海", 1, "B补强度=10%", "三级", true));
                break;
            case 4:
                infoList.add(getAlarmContentInfo(1, "战略进攻", 6, "B补强度=10%,C补强度=20%,订单达成率=30%,净G达成率=40%,近7天日均消耗=2000.58元", "一级", true));
                infoList.add(getAlarmContentInfo(1, "战略进攻", 5, "B补强度=10%,C补强度=20%,订单达成率=30%,净G达成率=40%,近7天日均消耗=2000.58元", "二级", true));
                infoList.add(getAlarmContentInfo(1, "战略进攻", 1, "B补强度=10%", "三级", true));
                break;
        }


        return infoList;
    }

    private AlarmContentInfo getAlarmContentInfo(
            Integer cityCnt, String cityNames, Integer indicatorCnt,
            String indicatorMessages, String level, Boolean onlyCity) {
        AlarmContentInfo contentInfo = new AlarmContentInfo();
        contentInfo.setCityCnt(cityCnt);
        contentInfo.setCityNames(cityNames);
        contentInfo.setIndicatorCnt(indicatorCnt);
        contentInfo.setIndicatorMessages(indicatorMessages);
        contentInfo.setLevel(level);
        contentInfo.setOnlyCity(onlyCity);
        return contentInfo;
    }
}
